<?php

require_once 'src/model/mServico.php';

class aServico extends mServico {
    /* datefomat ver data alua 06 
     * mysql : date_format(data_cad, '%s') as data_cad
     */
    protected $sqlInsert = "INSERT INTO servico(nome, descricao, precobase, desconto, isPromocao) VALUES ('%s','%s','%s','%s','%s' )";
    protected $sqlUpdate = "UPDATE servico SET nome='%s', descricao='%s', precobase='%s', desconto='%s', isPromocao='%s' WHERE idservico = '%s'";
    protected $sqlSelect = "SELECT * FROM servico WHERE 1=1 %s %s";
    protected $sqlDelete = "DELETE FROM servico WHERE idservico = '%s'";

    public function insert() {
        $sql = sprintf($this->sqlInsert, $this->getNome(), $this->getDescricao(), 
                $this->getPrecobase(), $this->getDesconto(), $this->getIspromocao());
        return $this->RunQuery($sql);
    }

    public function update() {
        $sql = sprintf($this->sqlUpdate, $this->getNome(), $this->getDescricao(), 
                $this->getPrecobase(), $this->getDesconto(), $this->getIspromocao(), 
                $this->getIdservico());
        return $this->RunQuery($sql);
    }

    public function delete() {
        $sql = sprintf($this->sqlDelete, $this->getIdservico());
        return $this->RunQuery($sql);
    }
    
    public function select($where='', $order='') {
        $sql = sprintf($this->sqlSelect, $where, $order);
        return $this->RunSelect($sql);
    }
    
    public function load() {
        $rs = $this->select(sprintf("and idservico='%s'", $this->getIdservico()));
        $this->setIdservico($rs[0]['idservico']);
        $this->setNome($rs[0]['nome']);
        $this->setDescricao($rs[0]['descricao']);
        $this->setPrecobase($rs[0]['precobase']);
        $this->setDesconto($rs[0]['desconto']);
        $this->setIspromocao($rs[0]['isPromocao']);
        return $this;
    }
    
}
